import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 关注，共享找房相关接口
 *
 * allen  2021-08-24
 */

/**
 * 查询关注列表
 * saleStatus:
 * 全部：0
 * SALE_ING(1, "销售中"),
    SALE_END(2, "停售"),
    SALE_WAITE(3, "待售"),
    PRE_SALE(4, "预售"),
    FORENSICS(5, "已取证"),
    WILL_FORENSICS(6, "即将取证")

    bedNumber:
    全部("全部"),
    ONE(1, "一室"),
    TWO(2, "二室"),
    THREE(3, "三室"),
    FOUR(4, "四室"),
    SIX(5, "四室及以上")
 */
const queryAttentionList = (data) => {
  return new Promise((resolve, reject) => {
    get("/users/favorites/index", {
      page: data.page,
      pageSize: data.pageSize,
      collectType: data.collectType,
      saleStatus: data.saleStatus,
      bedNumber: data.bedNumber
    }).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 关注/取关操作
 * collectType:
 *  NEW_HOUSE(1, "新房"),
    SECOND_HOUSE(2, "二手房"),
    RENT_HOUSE(3, "租房"),
    FORMAT(7, "户型")
 * @param {*} data 
 */
const attentionAction = (data) => {
  return new Promise((resolve, reject) => {
    post("/users/favorites/clickCollection", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}



/**
 * 批量取消关注
 * @param {*} data 
 */
const cancelAttentionAction = (data) => {
  return new Promise((resolve, reject) => {
    post("/users/favorites/batch/cancelCollection", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 关注统计(关注列表中的在售，已售，一室，二室等)
 * @param {*} collectionType 
 */
const attentionStatistics = (collectType) => {
  return new Promise((resolve, reject) => {
    get("/users/favorites/statistics?collectType=" + collectType).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 共享找房列表
 */
const queryShareHouseInfo = () => {
  return new Promise((resolve, reject) => {
    get("/user/customer/index").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}







module.exports = {
  queryAttentionList,
  cancelAttentionAction,
  queryShareHouseInfo,
  attentionAction,
  attentionStatistics
}
